import grails.test.*

class SubTaskTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
        mockDomain SubTask
        mockForConstraintsTests SubTask

        mockDomain Task
        mockForConstraintsTests Task
		
        mockDomain Project
        mockForConstraintsTests Project

        def SDQI = new Project(name:"SDQI", description: "An Agile Java Project.", startDate: new Date(), endDate: new Date() + 30, unitPerPhase: 5)
        def WAE = new Project(name:"WAE", description: "An Agile Ruby Project.", startDate: new Date() - 30, endDate: new Date() + 30, unitPerPhase: 10)
        def projects = [ SDQI, WAE ]
        
        projects*.save(flush:true)

        def tasks = [
            new Task(project: SDQI, name:"PSP0", description: "SD Real Number", startDate: new Date(2010, 8, 1), endPlanDate: new Date(2010, 8, 6), endDate: new Date(2010, 8, 7), hours: 5),
            new Task(project: SDQI, name:"PSP0.1", description: "LOC Counter", startDate: new Date(2010, 8, 1), endPlanDate: new Date(2010, 8, 6), endDate: new Date(2010, 8, 7), hours: 5),
            new Task(project: WAE,  name:"PS1", description: "Basics", startDate: new Date(2010, 8, 1), endPlanDate: new Date(2010, 8, 6), endDate: new Date(2010, 8, 7), hours: 5),
        ]
        tasks*.save(flush:true)
    }
	
    protected void tearDown() {
        super.tearDown()
    }
	
    void testSubTaskValidation() {
        def subTask = new SubTask()
        assertFalse subTask.validate()
    }
	
    void testSubTaskCreation() {
        def subTask = new SubTask()
        assertFalse subTask.validate()
		
        subTask.phaseName = "Planning"
        subTask.unitForPhase = 6.3
        subTask.estimatedTime = 20
        subTask.finalTime = 0

        assertFalse subTask.validate();
		
        def task1 = Task.findByName("PSP0")
        subTask.task = task1
        
        subTask.save()
        
        assertEquals 1, SubTask.list().size()
    }
}
